package com.atguigu.web.admin.controller.apartment;


import com.atguigu.common.result.Result;
import com.atguigu.model.entity.PaymentType;
import com.atguigu.web.admin.service.PaymentTypeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Tag(name = "支付方式管理")//给接口打标签、分组
@RequestMapping("/admin/payment")//定义该控制器下所有接口的访问路径URL
@RestController//控制器，会把方法返回值转为json再给前端
public class PaymentTypeController {

    @Autowired//依赖注入，把paymentTypeService的实例给Controller层用，这样就可以调用Service的方法
    private PaymentTypeService service;

    @Operation(summary = "查询全部支付方式列表")
    @GetMapping("list")
    public Result<List<PaymentType>> listPaymentType() {
        List<PaymentType> list = service.list();//调用PaymentTypeService
//        里面的list方法，查询支付方式数据。
    return Result.ok(list);//用Result.ok()将查询结果list包装成统一的json字符串再给前端
    }

    @Operation(summary = "保存或更新支付方式")
    @PostMapping("saveOrUpdate")
    public Result saveOrUpdatePaymentType(@RequestBody PaymentType paymentType) {
        service.saveOrUpdate(paymentType);
        return Result.ok();
    }


    @Operation(summary = "根据ID删除支付方式！")
    @DeleteMapping("deleteById")
    public Result deletePaymentById(@RequestParam Long id) {
        service.removeById(id);
//        调用Service的removeById方法，返回前端一个ok
        return Result.ok();
    }

}















